<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>第二件半价</title>
    <script>
      function getHalfPrice(price, amount) {
        let cost = parseInt(amount / 2) * price + parseInt(amount / 2) * (price / 2)
        if (amount % 2 != 0) {
          cost += price - 0
        }
        return cost
      }

      let price = prompt('请您输入商品的单价: ')
      let amount = prompt('请您输入购买数量: ')
      let cost = getHalfPrice(price, amount)
      document.write('您一共需要花费: ' + cost + ' ¥')
    </script>
  </head>
  <body></body>
</html>
